import request from '@/utils/request'

const api_name = '/admin/system/sysRole'

export default {
  findAll() {
    return request({
      url: `${api_name}/findAll`,
      method: 'get'
    })
  },
  //获取角色分页列表(带搜索)
  getPageList(pageNum, pageSize, searchObj) {
    return request({
      url: `${api_name}/${pageNum}/${pageSize}`,
      method: 'get',
      params: searchObj
    })
  },
  //单个删除角色
  removeById(id) {
    return request({
      url: `${api_name}/remove/${id}`,
      method: 'delete'
    })
  },
  //保存角色
  save(role) {
    return request({
      url: `${api_name}/save`,
      method: 'post',
      data: role
    })
  },
  //根据id获取角色数据
  getById(id) {
    return request({
      url: `${api_name}/get/${id}`,
      method: 'get'
    })
  },
  //更新
  updateById(role) {
    return request({
      url: `${api_name}/update`,
      method: 'put',
      data: role
    })
  },
  //批量删除
  batchRemove(idList) {
    return request({
      url: `${api_name}/batchRemove`,
      method: `delete`,
      data: idList
    })
  },
  //查询用户的角色
  getRoles(userId) {
    return request({
      url: `${api_name}/toAssign/${userId}`,
      method: 'get'
    })
  },
  //分配角色
  assignRoles(assignObj) {
    return request({
      url: `${api_name}/doAssign`,
      method: 'post',
      data: assignObj
    })
  },
}